<template>
    <div id="topiclist">

        <div 
            class="topiclist-container"
            v-for="(item,index) in topic"
            :key="index"
            @click="goToDetail(item.id)">
            <img :src="item.pic" alt="">
            <div class="topiclist-container-box">
                <div class="topiclist-container-box-title">{{item.title}}</div>
                <div class="topiclist-container-box-desc">{{item.descript}}</div>
                <div class="button">查看详情</div>
            </div>
        </div>

        
    </div>
</template>

<script>
export default {
    data() {
        return {
            // 详情
            topic:[],
        }
    },
    mounted() {
        // 精选专题 详情 \ 新闻列表
        this.$API.topic().then((res)=>{
            console.log(res.data.data);
            this.topic = res.data.data;
        }).catch((error)=>{
            console.log(error);
        });
    },
    methods: {
        // 点击 跳转详情页
        goToDetail(id){
            this.$router.push({
                path:"/TopDetail",
                query:{
                    id,
                }
            })
        }
    },
}
</script>

<style lang="scss" scoped>
#topiclist{
    width:100%;
    height:100%;
    .topiclist-container{
        width:7.2rem;
        text-align: left;
        margin-left:0.15rem;
        position: relative;
        img{
            width:100%;
            height:3.8rem;
            border-radius: 0.1rem;
        }
        .topiclist-container-box{
            width:100%;
            margin:0 10%;
            position: absolute;
            top: 0.7rem;
            line-height: 0.65rem;
            color:#fff;
            z-index: 999;
            .topiclist-container-box-title{
                width:80%;
                font-size: 0.4rem;
                margin:0.1rem 0;
                white-space: nowrap; //强制不换行
                overflow: hidden; //超出部分隐藏
                text-overflow: ellipsis; //显示‘...’
            }
            .topiclist-container-box-desc{
                width:80%;
                margin:0.15rem 0;
                font-size: 0.3rem;
                white-space: nowrap; //强制不换行
                overflow: hidden; //超出部分隐藏
                text-overflow: ellipsis; //显示‘...’
            }
            .button{
                width:30%;
                font-size: 0.3rem;
                border:0.01rem solid white;
                border-radius: 0.5rem;
                text-align: center;
                margin-left: 1.5rem;
            }
        }
    }
}   
</style>